<%--
  Created by IntelliJ IDEA.
  User: Alan4
  Date: 2023/1/31
  Time: 3:55
  To change this template use File | Settings | File Templates.
--%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page isELIgnored="false"%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    </div>
</body>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/util/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/util/sweetalert2.min.css" />
<script src="${pageContext.request.contextPath}/util/jquery-3.6.3.min.js"></script>
<script src="${pageContext.request.contextPath}/util/sweetalert2.min.js"></script>
<script src="${pageContext.request.contextPath}/util/bootstrap.min.js"></script>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/head.css" />
<script src="${pageContext.request.contextPath}/public/head.js" type="module"></script>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/oneself.css" />
<script src="${pageContext.request.contextPath}/public/oneself.js" type="module"></script>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/department.css" />
<script src="${pageContext.request.contextPath}/public/department.js" type="module"></script>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/user.css" />
<script src="${pageContext.request.contextPath}/public/user.js" type="module"></script>

<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/public/task.css" />
<script src="${pageContext.request.contextPath}/public/task.js" type="module"></script>

<script type="text/javascript">
    let baseUrl = "http://localhost:8080"
	function promptSuccess (title) {
		Swal.mixin({
		  toast: true,
		  position: 'top-end',
		  showConfirmButton: false,
		  timer: 4000
		}).fire({
		  type: "success",
		  title
		})
	}
	//失败弹窗
	function promptError (title) {
		Swal.mixin({
		  toast: true,
		  position: 'top-end',
		  showConfirmButton: false,
		  timer: 4000
		}).fire({
		  type: "error",
		  title
		})
	}
	function post (path, data, success) {
		$.ajax({
			 url:baseUrl + path,
			 dataType:"json",
			 type:"post",
			 // async:"true/false",
			 data,
			 success,
			 error:function(){
				 Swal.mixin({
				   toast: true,
				   position: 'top-end',
				   showConfirmButton: false,
				   timer: 4000
				 }).fire({
				   type: "error",
				   title: "系统异常，请联系管理员。"
				 })
			 }
		})
	}
	//封装的get请求
	function get (path, data, success) {
		$.ajax({
			 url:baseUrl + path,
			 dataType:"json",
			 type:"get",
			 // async:"true/false",
			 data,
			 success,
			 error:function(){
				 Swal.mixin({
				   toast: true,
				   position: 'top-end',
				   showConfirmButton: false,
				   timer: 4000
				 }).fire({
				   type: "error",
				   title: "系统异常，请联系管理员。"
				 })
			 }
		})
	}
	function clickSelectInputTextAll(event){
		event.select();
	}
	function userUpdateModelBtn(code){
		get("/department/getall.do",{},function (res){
			if(res.code === 200){
				 var depData = res.data;
				 for (var i = 0; i < depData.length; i++) {
					 var option = document.createElement("option")
					 option.setAttribute("value", depData[i].id)
					 option.text = depData[i].name
					$("#user-update-department").append(option)
				 }
				get("/user/_update.do", {code: code}, function(res){
					var departmentId = 0;
					if(res.code === 200){
						console.log(depData);
						for (var i = 0; i < depData.length; i++) {
							if(res.data.department === depData[i].name){
								departmentId = depData[i].id;
							}
						}
						console.log(res);
						console.log(departmentId);
						$("#user-update-code").val(res.data.code)
						$("#user-update-name").val(res.data.userName)
						$("#user-update-gender").val(res.data.gender)
						$("#user-update-birthDate").val(res.data.birthDate)
						$("#user-update-jobTitle").val(res.data.jobTitle)
						$("#user-update-education").val(res.data.education)
						$("#user-update-degree").val(res.data.degree)
						$("#user-update-QQ").val(res.data.qq)
						$("#user-update-email").val(res.data.email)
						$("#user-update-introduction").val(res.data.introduction)
						$("#user-update-password").val(res.data.password)
						$("#user-update-department").val(departmentId)
					}else{
						setTimeout(function(){
							$("#updateUserModal").modal("hide")
						}, 800)
						 promptError(res.msg)
					}
				 })
			}else{
				 promptError(res.msg)
			}
		})
		// paging(1, $("#user-set-page-size option:selected").val(), $("#user-search").val(), $("#user-select-departments option:selected").val())
	}
	function publishTask(that){
		console.log(that.id);
		let taskCode = that.id.split("TASK")[1]
		let endTime = $("#" + that.id).parent().prev().children().val()
		post("/announce/announce.do", {taskCode, endTime}, function(res){
			if(res.code === 200){
				promptSuccess(res.msg)
                $("#publishModal").modal("hide")
                // window.location.href = common.baseUrl + "/task/list.do";
                // setTimeout(function () {
                    window.location.href = baseUrl + "/task/list.do"
                // }, 1000)
            }else{
				promptError(res.msg)
			}
		})
	}
	function fulfilTask(id){
		console.log(id)
		$("#task-fulfil-id").val(id)
		$("#fulfilTaskModal").modal("show")

	}
	function taskExportExcel(id){
		const xhr = new XMLHttpRequest();
		xhr.open('get', baseUrl + '/report/export/excel.export?id=' + id);
		xhr.responseType = "blob";
		xhr.addEventListener('load', () => {
		  if (xhr.status === 200) {
		    // var blob = new Blob([xhr.responseText], { type: "application/vnd.ms-excel" });//2003
		    var blob = new Blob([xhr.response], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;" }); // 2007
		    var url = window.URL.createObjectURL(blob);
		    let a = document.createElement("a");
		    a.href = url
		    a.download = '健康上报.xlsx';
		    a.click();
		  }
		});
		xhr.send();

	}
	// setInterval(function(){
	// 	console.log("1");
	// }, 3000);
	// setInterval(function(){
	// 	console.log("2");
	// }, 3000);
</script>
</html>